define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'prison/detention_prison/index' + location.search,
                    add_url: 'prison/detention_prison/add',
                    edit_url: 'prison/detention_prison/edit',
                    del_url: 'prison/detention_prison/del',
                    multi_url: 'prison/detention_prison/multi',
                    import_url: 'prison/detention_prison/import',
                    table: 'detention_prison',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'province_id', title: __('Province_id')},
                        {field: 'province.name', title: __('Province.name')},
                        // {field: 'city_id', title: __('City_id')},
                        {field: 'city.name', title: __('City.name')},
                        // {field: 'area_id', title: __('Area_id')},
                        {field: 'area.name', title: __('Area.name')},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'lng', title: __('Lng'), operate: 'LIKE'},
                        {field: 'lat', title: __('Lat'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1')}, formatter: Table.api.formatter.normal},
                        {field: 'tel', title: __('Tel'), operate: 'LIKE'},
                        {field: 'address_verify', title: __('Address_verify'), searchList: {"0":__('Address_verify 0'),"1":__('Address_verify 1')}, formatter: Table.api.formatter.normal},
                        {field: 'communication_verify', title: __('Communication_verify'), searchList: {"0":__('Communication_verify 0'),"1":__('Communication_verify 1')}, formatter: Table.api.formatter.normal},
                        {field: 'mail_type', title: __('Mail_type'), searchList: {"0":__('Mail_type 0'),"1":__('Mail_type 1'),"-1":__('Mail_type -1')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'mail_method', title: __('Mail_method'), searchList: {"0":__('Mail_method 0'),"1":__('Mail_method 1'),"-1":__('Mail_method -1')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
